<template>
	<view class="scrollPage">
		<u-navbar :border-bottom="false" title="海报选择" back-icon-color="#ffffff" :background="{background:'#2149c3'}"
		 title-color="#ffffff"></u-navbar>
		<view class="flex_box">
			<view class="flex-sub">
				<view class="img_row" v-for="(item,index) in PosterList" :key="index"  @click="imgclick(item)">
					<view class="num">{{index+1}}</view>
					<u-image :showLoading="true" :src="url + item.cover" width="300" height="400"></u-image>
				</view>
			</view>
			<!-- <pagePination :total="page.total" :pageSize="page.pagesize" mode="simple" :showAround="true" @change="pageChange" class="page_box"></pagePination> -->
			<pagePination :total="page.total" :pageSize="page.pagesize" :currentPage="page.pagenum" @change="pageChange" class="page_box"></pagePination>
			<view @click="goPosterUpload()" class="solid_add">+</view>
		</view>

	</view>

</template>

<script>
	var _self;
	import pagePination from '../../components/page-pagination/page-pagination.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				url:'',
				PosterList: [
					{cover:''}
				],
				imgLists: [],
				page: {
					pagenum: 1,
					pagesize: 10,
					total: 10,
				}
			}
		},
		components: {
			pagePination
		},
		onShow() {
			// this.PosterList();
		},
		onLoad() {
			this.posterList();
			_self = this;
		},
		computed: {
			...mapState(['userInfo', 'hasLogin', 'scene', 'openid'])
		},
		filters:{
			flterimg(img){
				console.log(img)
			}
		},
		methods: {
			pageChange(currentPage, type){
				// this.page.currentPage = currentPage;
			      // console.log("点击了" + type +"，当前页：" + currentPage);
				  this.page.pagenum = currentPage;
				  this.page.pagesize = 10
				  this.posterList();
			},
			goPosterSave(id) {
				uni.navigateTo({
					url: '/pageB/poster/poster-save/poster-save?id=' + id
				})
			},
			goPosterUpload() {
				// uni.navigateTo({
				// 	url: '/pages/poster/poster-upload/poster-upload'
				// })
				uni.chooseImage({
					count: 1,
					sizeType: ['original'],
					success: function(res) {
						// _self.uploadFiles(res.tempFilePaths)
						uni.redirectTo({
							url: '/newpage/edithbimage/edit-image?imgurlobj=' + res.tempFilePaths[0]
						})
					},
					fail: function() {
						// uni.hideLoading();
					}
				});
			},
			imgclick(item){
				uni.navigateTo({
					url: '/pageB/poster/poster-save/poster-save?imgurlobj=' + JSON.stringify(item.cover)
				})
			},
			// uploadFiles(f) {
			// 	console.log(f, '					ffff')
			// 	uni.uploadFile({
			// 		url: this.serverUrl + 'app/upload',
			// 		header: {
			// 			"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
			// 		},
			// 		filePath: f[0],
			// 		name: 'file',
			// 		method: "POST",
			// 		formData: {
			// 			username: "",
			// 		},
			// 		success: (r) => {
			// 			let imgData = JSON.parse(r.data);
			// 			uni.navigateTo({
			// 				url: '/pages/poster/poster-save/poster-save?imgurlobj=' + JSON.stringify(imgData.fileName)
			// 			})
			// 		},
			// 		fail: (r) => {
			// 			uni.showToast({
			// 				title:"上传失败",
			// 			})
			// 		},
			// 		complete: (r) => {

			// 		}
			// 	});
			// },
			posterList: function() {
				this.url = this.serverUrl
				uni.request({
					url: this.serverUrl + 'app/getPosterList',
					header: {
						"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
					},
					method: 'POST',
					data: {
						memberId: '',
						status:1,
						pageSize: this.page.pagesize,
						pageNum: this.page.pagenum
					},
					success: (r) => {
						if (r.data.code == 0) {
							this.PosterList = r.data.data;
							this.page.total = r.data.count;
						}
					}
				})
			}
		}
	}
</script>

<style>
	.solid_add {
		width: 100rpx;
		height: 100rpx;
		background-color: #0081ff;
		color: #FFFFFF;
		font-size: 80rpx;
		border-radius: 50%;
		font-weight: 300;
		display: inline-block;
		text-align: center;
		line-height: 90rpx;
		position: fixed;
		z-index: 1;
		right: 30rpx;
		bottom: 200rpx;
	}
	.flex_box{
		display: flex;
		flex: 1;
		flex-direction: column;
	}
	.flex-sub{
		display: flex;
		flex-wrap: wrap;
		flex: 1;
	}
	.img_row{
		width: 48%;
		display: flex;
		padding: 20rpx;
		border-radius: 10rpx;
		border: 1px solid #EEEEEE;
		margin-right: 20rpx;
		margin-bottom: 20rpx;
		align-items: center;
		justify-content: center;
		position: relative;
	}
	.img_row:nth-child(even){
		margin-right: 0rpx;
	}
	.num{
		position: absolute;
		background-color: rgba(0,0,0,0.7);
		color: #FFFFFF;
		bottom: 0;
		right: 0;
		width: 50rpx;
		height: 50rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 1;
	}
</style>
